#'
#' calculate the alpha level of confidence interval
#' 
#' @param data a numeric vector
#' @param alpha the significant level should be used to find the confidence interval
#' @param alternative the alternative hypothesis
#' @param na.rm a logical flag to remove the NA in data or not
#' 
#' 

conf=function(data,alpha=0.05,alternative="both",na.rm=FALSE){
  if(na.rm==TRUE){
    data=data[!is.na(data)]
  }
  
  n=length(data)
  if(alternative=="both"){
    lowindex=floor(n*alpha/2)
    upindex=ceiling(n*(1-alpha/2))
  }else if(alternative=="less"){
    lowindex=floor(n*alpha)
    upindex=n
  }else if(alternative=="greater"){
    lowindex=1
    upindex=ceiling(n*(1-alpha))
  }else{
    stop("please given a right alternative hypothesis")
  }
  
  data=sort(data)
  if(lowindex==0)
    lowindex=1
  return(data[c(lowindex,upindex)])
}